<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 业绩排行 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <el-tabs v-model="activeName" @tab-click="tabClick">
        <el-tab-pane label="个人业绩排行" name="1"></el-tab-pane>
        <el-tab-pane label="个人客户类型" name="2"></el-tab-pane>
        <el-tab-pane label="区域业绩排行" name="3"></el-tab-pane>
        <el-tab-pane label="区域客户类型" name="4"></el-tab-pane>
      </el-tabs>
      <div class="handle-box">
        <el-date-picker v-model="query.time" class="mr10" type="month" placeholder="请选择月份"></el-date-picker>
        <el-input v-model="query.kw" placeholder="请输入经理姓名查询" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-if="activeName == '1'" v-loading="tableLoad" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                @sort-change='personmoneyList'>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="经理姓名"></el-table-column>
        <el-table-column prop="signAmount" sortable='custom' label="本月签单金额"></el-table-column>
        <el-table-column prop="successAmount" sortable='custom' label="本月下款金额"></el-table-column>
        <el-table-column prop="incomeAmount" sortable='custom' label="创收"></el-table-column>
      </el-table>
      <el-table v-if="activeName == '2'" v-loading="tableLoad" :data="tableData" border class="table" style="width: 100%" ref="multipleTable">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="经理姓名"></el-table-column>
        <el-table-column prop="count" label="总数"></el-table-column>
        <el-table-column prop="a" label="A级"></el-table-column>
        <el-table-column prop="b" label="B级"></el-table-column>
        <el-table-column prop="c" label="C级"></el-table-column>
      </el-table>
      <el-table v-if="activeName == '3'" v-loading="tableLoad" :data="tableData" border class="table" style="width: 100%" ref="multipleTable"
                @sort-change='regionmoneyList'>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="区域名称"></el-table-column>
        <el-table-column prop="signAmount" sortable='custom' label="本月签单金额"></el-table-column>
        <el-table-column prop="successAmount" sortable='custom' label="本月下款金额"></el-table-column>
        <el-table-column prop="incomeAmount" sortable='custom' label="创收"></el-table-column>
      </el-table>
      <el-table v-if="activeName == '4'" v-loading="tableLoad" :data="tableData" border class="table" style="width: 100%" ref="multipleTable">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="区域名称"></el-table-column>
        <el-table-column prop="count" label="总数"></el-table-column>
        <el-table-column prop="a" label="A级"></el-table-column>
        <el-table-column prop="b" label="B级"></el-table-column>
        <el-table-column prop="c" label="C级"></el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total,sizes, prev, pager, next" :current-page="query.page" :page-size="query.limit"
                       :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]" :total="query.totalCount" :pager-count="5"
                       @size-change="handlePageSelectChange" @current-change="handlePageChange" @prev-click="handlePageChange"
                       @next-click="handlePageChange"></el-pagination>
      </div>
    </div>
  </div>
  </div>
</template>
<script>

import { performancePersonalPerformance, performanceIndividualCustomerType, performanceRegionalPerformanceRanking, performanceRegionalCustomerType } from '../../../api/index';

export default {
  data() {
    return {
      query: {
        page: 1,
        limit: 10,
        totalCount: 0,
        time: '',
        kw: '',
        sort: '',//1签单金额升序 2签单金额倒叙 3下款金额升序 4下款金额倒叙 5创收升序 6创收倒叙
      },
      activeName: '1',
      tableData: [],
      tableLoad: false,
    }
  },
  created() {
    this.getList();
  },
  methods: {
    //初始化列表数据
    getList() {
      switch (this.activeName) {
        case '1': this.performancePersonalPerformanceAjax(); break;
        case '2': this.performanceIndividualCustomerTypeAjax(); break;
        case '3': this.performanceRegionalPerformanceRankingAjax(); break;
        case '4': this.performanceRegionalCustomerTypeAjax(); break;
      }
    },
    //个人业绩排行初始化
    performancePersonalPerformanceAjax() {
      this.tableLoad = true;
      performancePersonalPerformance({
        page: this.query.page,
        limit: this.query.limit,
        month: this.query.time,
        kw: this.query.kw,
        orderType: this.query.sort
      }).then(res => {
        this.tableLoad = false;
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //个人客户类型初始化
    performanceIndividualCustomerTypeAjax() {
      this.tableLoad = true;
      performanceIndividualCustomerType({
        page: this.query.page,
        limit: this.query.limit,
        month: this.query.time,
        kw: this.query.kw,
      }).then(res => {
        this.tableLoad = false;
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //区域业绩排行初始化
    performanceRegionalPerformanceRankingAjax() {
      this.tableLoad = true;
      performanceRegionalPerformanceRanking({
        page: this.query.page,
        limit: this.query.limit,
        month: this.query.time,
        kw: this.query.kw,
        orderType: this.query.sort
      }).then(res => {
        this.tableLoad = false;
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //区域客户类型初始化
    performanceRegionalCustomerTypeAjax() {
      this.tableLoad = true;
      performanceRegionalCustomerType({
        page: this.query.page,
        limit: this.query.limit,
        month: this.query.time,
        kw: this.query.kw,
      }).then(res => {
        this.tableLoad = false;
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getList();
    },
    //列表切换
    tabClick() {
      this.query.page = 1;
      this.query.time = '';
      this.query.kw = '';
      this.getList();
    },
    //切换页数
    handlePageSelectChange(limit) {
      this.query.limit = limit;
      this.query.page = 1;
      this.getList();
    },
    //翻页
    handlePageChange(page) {
      thiss.query.page = page;
      this.getList();
    },
    //个人业绩排序
    personmoneyList(column, prop, order) {
      switch (column.prop) {
        case 'signAmount': this.query.sort = column.order == 'ascending' ? '1' : column.order == 'descending' ? '2' : ''; break;
        case 'successAmount': this.query.sort = column.order == 'ascending' ? '3' : column.order == 'descending' ? '4' : ''; break;
        case 'incomeAmount': this.query.sort = column.order == 'ascending' ? '5' : column.order == 'descending' ? '6' : ''; break;
      }
      this.query.page = 1;
      this.getList();
    },
    //区域业绩排序
    regionmoneyList(column, prop, order) {
      switch (column.prop) {
        case 'signAmount': this.query.sort = column.order == 'ascending' ? '1' : column.order == 'descending' ? '2' : ''; break;
        case 'successAmount': this.query.sort = column.order == 'ascending' ? '3' : column.order == 'descending' ? '4' : ''; break;
        case 'incomeAmount': this.query.sort = column.order == 'ascending' ? '5' : column.order == 'descending' ? '6' : ''; break;
      }
      this.query.page = 1;
      this.getList();
    }
  }
}
</script>
<style scoped>
.handle-input {
    width: 300px;
}
.mr10 {
    margin-right: 10px;
}
</style>